#include "libLUI_in.h"

/*
 * Basic Structures
 */

struct LUIRectangle LUIRectangle( int left , int top , int width , int height )
{
	struct LUIRectangle	rect ;
	
	rect.left = left ;
	rect.top = top ;
	rect.width = width ;
	rect.height = height ;
	
	return rect;
}

/*
 * Internal
 */

int LUILoadWallpaper( struct LUIWindowsManager *windows_manager , char *wallpaper_pathfilename_format , ... )
{
	va_list			valist ;
	struct RBGA		wallpaper_bg_color_default = { 0x14 , 0x6A , 0x44 , 0 } ;
	struct BitmapContext	*wallpaper_context = NULL ;
	
	if( wallpaper_pathfilename_format == NULL )
	{
		wallpaper_context = CreateBitmapContext( windows_manager->screen_rect.width , windows_manager->screen_rect.height , LIBBMP_PLANES_1 , LIBBMP_BITCOUNT_24 , LIBBMP_COMPRESSION_NONE , 0 , 0 , 0 , & wallpaper_bg_color_default ) ;
	}
	else
	{
		va_start( valist , wallpaper_pathfilename_format );
		wallpaper_context = ReadBitmapFileV( wallpaper_pathfilename_format , valist ) ;
		va_end( valist );
	}
	if( wallpaper_context == NULL )
		return -1;
	
	if( windows_manager->wallpaper_context )
	{
		FreeBitmapContext( windows_manager->wallpaper_context );
	}
	
	windows_manager->wallpaper_context = wallpaper_context ;
	
	windows_manager->wallpaper_rect.width = GetBitmapWidth( windows_manager->wallpaper_context ) ;
	if( windows_manager->wallpaper_rect.width > windows_manager->screen_rect.width )
		windows_manager->wallpaper_rect.width = windows_manager->screen_rect.width ;
	windows_manager->wallpaper_rect.height = GetBitmapHeight( windows_manager->wallpaper_context ) ;
	if( windows_manager->wallpaper_rect.height > windows_manager->screen_rect.height )
		windows_manager->wallpaper_rect.height = windows_manager->screen_rect.height ;
	
#if 0
	printf( "Wallpaper file : " );
	vprintf( wallpaper_pathfilename_format , valist );
	printf( "(null)" );
	
	printf( "Wallpaper width[%d]\n" , GetBitmapWidth(windows_manager->wallpaper_context) );
	printf( "Wallpaper height[%d]\n" , GetBitmapHeight(windows_manager->wallpaper_context) );
	printf( "Wallpaper planes[%d]\n" , GetBitmapPlanes(windows_manager->wallpaper_context) );
	printf( "Wallpaper bit count[%d]\n" , GetBitmapBitCount(windows_manager->wallpaper_context) );
	printf( "Wallpaper compression[%d]\n" , GetBitmapCompression(windows_manager->wallpaper_context) );
	printf( "Wallpaper size image[%d]\n" , GetBitmapSizeImage(windows_manager->wallpaper_context) );
	printf( "Wallpaper x pels per meter[%d]\n" , GetBitmapXPelsPerMeter(windows_manager->wallpaper_context) );
	printf( "Wallpaper y pels per meter[%d]\n" , GetBitmapYPelsPerMeter(windows_manager->wallpaper_context) );
	printf( "Wallpaper clr used[%d]\n" , GetBitmapClrUsed(windows_manager->wallpaper_context) );
	printf( "Wallpaper clr important[%d]\n" , GetBitmapClrImportant(windows_manager->wallpaper_context) );
#endif
	
	return 0;
}

void LUIShowAllWindows( struct LUIWindowsManager *windows_manager )
{
	struct LUIWindow	*window = NULL ;
	
	list_for_each_entry( window , & (windows_manager->windows_list.this_listnode) , struct LUIWindow , this_listnode )
	{
		if( TEST_PROPERTY(window->properties,LUIWINDOW_PROPERTY_SHOW) && window->pfuncLUIDrawWindowProc )
		{
			window->pfuncLUIDrawWindowProc( window );
		}
	}
	
	return;
}

void LUISetRefreshScreenFlag( struct LUIWindowsManager *windows_manager )
{
	windows_manager->refresh_screen_flag = 1 ;
	return;
}

void LUIUnsetRefreshScreenFlag( struct LUIWindowsManager *windows_manager )
{
	windows_manager->refresh_screen_flag = 0 ;
	return;
}

int LUIIsSetRefreshScreenFlag( struct LUIWindowsManager *windows_manager )
{
	return windows_manager->refresh_screen_flag;
}

